<?php
global $_GPC,$_W;
$weid=intval($_W['uniacid']);
load()->func('tpl');
$operation=!empty($_GPC['op']) ? $_GPC['op'] : 'display';
if($operation == 'display'){
    $gunweizhi=pdo_fetchall("SELECT * FROM ".tablename('bbyscm_card_gun')." WHERE uniacid = '{$_W['uniacid']}' ");
} elseif($operation == 'post') {
    $id=intval($_GPC['id']);
    if(!empty($id)){
        $gunweizhi=pdo_fetch("SELECT * FROM ".tablename('bbyscm_card_gun')." WHERE id = '$id'");
    }
    if(checksubmit('submit')){
        $data=array(
		'uniacid'=>$_W['uniacid'], 
		'name'=>$_GPC['catename'],
		'url'=>trim($_GPC['url']),
	    'start_time'=> strtotime($_GPC['activity']['start']),
		'end_time'=> strtotime($_GPC['activity']['end']),
		'createtime'=> time(),
		);
        if(!empty($id)){
            pdo_update('bbyscm_card_gun', $data, array('id'=>$id));
        } else {
            pdo_insert('bbyscm_card_gun', $data);
            $id=pdo_insertid();
        }
        message('更新流动文字成功！', $this->createWebUrl('gunweizhi', array('op'=>'display')), 'success');
    }

} elseif($operation == 'delete') {
    $id=intval($_GPC['id']);
    $category=pdo_fetch("SELECT id FROM ".tablename('bbyscm_card_gun')." WHERE id = '$id'");
    if(empty($category)){
        message('抱歉，流动文字不存在或是已经被删除！', $this->createWebUrl('gunweizhi', array('op'=>'display')), 'error');
    }
    pdo_delete('bbyscm_card_gun', array('id'=>$id));
    message('流动文字删除成功！', $this->createWebUrl('gunweizhi', array('op'=>'display')), 'success');
}elseif ('shenhe' == $operation) {
			$id = intval($_GPC['id']);
			$issend = intval($_GPC['key']) == 1 ? 0 : 1;
			$data1 = array('key' => $issend);
			pdo_update('bbyscm_card_gun', $data1, array('id' => $id));

			if ($issend == 1) {
				echo json_encode(array('a' => 1));
				return NULL;
			}

			echo json_encode(array('a' => 0));
			return NULL;
		}

include $this->template('web/gunweizhi');